package com.compty.paint.manager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.compty.core.hibernate.HibernateEntityDao;
import com.compty.paint.domain.UploadState;

/**
 * @Todo:上传状态Manager (正常、隐藏、删除)
 * @author: 朱庆辉
 * @CreateTime:2012-4-12 上午11:05:15
 */
public class UploadStateManager  extends HibernateEntityDao<UploadState>{
	
	private static Map<String,UploadState> uploadStateMap = new HashMap<String, UploadState>();
	
	private static List<UploadState> uploadStateList = null;
	
	public UploadState findUniqueBy(String fieldName, Object value){
		
		if("english_name".equals(fieldName)){
			if(uploadStateMap.size() == 0){
				List<UploadState>  list = getAll();
				for (UploadState uploadState : list) {
					String key = uploadState.getEnglish_name();
					uploadStateMap.put(key, uploadState);
				}
			}
			
			return uploadStateMap.get(value);
		}
		else{
			return super.findUniqueBy(fieldName, value);
		}
	}
	
	public List<UploadState> getAll(){
		if(uploadStateList == null){
			return super.getAll();
		}else{
			return uploadStateList;
		}
	}

}
